import { createRouter, createWebHistory } from 'vue-router'
import AIChat from '../views/AIChat.vue'
import Login from '../views/Login.vue'

const routes = [
  {
    path: '/',
    name: 'AIChat',
    component: AIChat
    // 移除 requiresAuth，允许未登录用户访问聊天界面
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token')

  if (to.path === '/login' && token) {
    // 如果已登录但访问登录页，重定向到首页
    next('/')
  } else {
    // 允许访问所有页面
    next()
  }
})

export default router 